local nieyi = fk.CreateSkill {
  name = "3s__nieyi",
  tags = { Skill.Compulsory },
  dynamic_desc = function(self, player)
    if player:getMark("nieyi_fix") == 0 then
      return "3s__nieyi"
    else
      return "3s__nieyi_fix"
    end
  end,
}

Fk:loadTranslationTable{
  ["3s__nieyi"] = "臬义",
  [":3s__nieyi"] = "锁定技，目标<font color='red'>有</font>你的锦囊牌结算中，你拥有“看破”，目标<font color='red'>无</font>你的【杀】结算中，你拥有“慷忾”。",
  [":3s__nieyi_fix"] = "锁定技，目标<font color='red'>无</font>你的锦囊牌结算中，你拥有“看破”，目标<font color='red'>有</font>你的【杀】结算中，你拥有“慷忾”。",
}

nieyi:addEffect(fk.AfterCardTargetDeclared, {
  anim_type = "support",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(nieyi.name) and #data:getAllTargets() > 0 then
     if data.card.type == Card.TypeTrick then
      if player:getMark("nieyi_fix") == 0 then
        return table.contains(data:getAllTargets(), player)
      else
        return not table.contains(data:getAllTargets(), player)
      end  
     elseif data.card.trueName == "slash" then
      if player:getMark("nieyi_fix") > 0 then
        return table.contains(data:getAllTargets(), player)
      else
        return not table.contains(data:getAllTargets(), player)
      end
     end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local skill = ""
    if data.card.type == Card.TypeTrick then
       skill = "3s__kanpo"
    elseif data.card.trueName == "slash" then
       skill = "3s__kangkai"
    end
    data.extra_data = data.extra_data or {}
    data.extra_data.nieyi = skill
    room:handleAddLoseSkills(player, skill)
  end,
})

nieyi:addEffect(fk.CardUseFinished, {
  mute = true,
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(nieyi.name) and data.extra_data then
      return data.extra_data.nieyi and player:hasSkill(data.extra_data.nieyi)
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local skill = data.extra_data.nieyi
    room:handleAddLoseSkills(player, "-" .. skill)
  end,
})


return nieyi